package com.Ajava1704.for定时线程池的使用;

import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * 作者: LCG
 * 日期: 2020/2/11 09:52
 * 描述:
 */
public class ForConnRunable implements Runnable {

    private ScheduledExecutorService scheduledExecutorService;

    public ForConnRunable(ScheduledExecutorService scheduledExecutorService) {
        this.scheduledExecutorService = scheduledExecutorService;
    }

    private static int i=0;

    @Override
    public void run() {

        if(i<3){
            try {
                i++;
                Thread.sleep(2000);
                System.out.println("=============执行重连======");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }else{
            System.out.println("========记录重连的异常=====重连失败===");
            scheduledExecutorService.shutdown();
        }

    }
}
